# -*- coding: utf-8 -*-

"""
运行用例集：
    python3 run.py

# '--allure_severities=critical, blocker'
# '--allure_stories=测试模块_demo1, 测试模块_demo2'
# '--allure_features=测试features'
# '--html=Report/report.html' 使用pytest-html生成HTML报告,--self-contained-html使用该参数，则生成的css和HTML合为一个文件

"""
import pytest, sys

from Common import Log, Config
from Common import Shell
from TestCase.dataPrepare import OBSYS
import os

if __name__ == '__main__':
    conf = Config.Config()
    log = Log.MyLog()
    log.info('初始化配置文件, path=' + conf.conf_path)

    shell = Shell.Shell()
    report_path = str(os.path.dirname(os.path.abspath(__file__)))
    xml_report_path = report_path + '\\Report\\xml'
    html_report_path = report_path + '\\Report\\html'

    option = Config.Config().get_conf('comm', 'option')
    if option == '1':
        # -------------------该部分用于创建测试订单-------------------
        allure_list = '--allure_features=createOrder'
        args = ['-x', '-s', '-q', '--alluredir', xml_report_path, allure_list, '--html=Report/report.html',
                '--self-contained-html']
        log.info('执行用例集为：%s' % allure_list)
        pytest.main(args)

    if option == '2':
        # -------------------该部分用于小黄人验货-------------------
        orderNum = Config.Config().get_conf('comm', 'orderNum')

        # 判断订单回收方式（门店、上门、物流）,并把基本信息写入文件中用于质检操作
        o = OBSYS()
        o.login()
        o.getOrderInfo(orderNum)
        orderInfos = o.readOrderInfo()

        # 根据订单类型，使用不同的质检方式
        if len(orderInfos) > 1:
            # 定义测试集
            allure_list = '--allure_features=littleYellowMan'
            args = ['-x', '-s', '-q', '--alluredir', xml_report_path, allure_list, '--html=Report/report.html',
                    '--self-contained-html']
            log.info('执行用例集为：%s' % allure_list)
            pytest.main(args)

            # from Common import Email
            # try:
            #     mail = Email.SendMail()
            #     mail.sendMail()
            # except:
            #     log.error('发送邮件失败，请检查邮件配置')
            #     raise
        else:
            print('该订单回收方式为【物流】')
            from TestCase.inspectionOperation import InspectionOperation

            InspectionOperation().InspectionProduct()
            InspectionOperation().tally()

